﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using System.Threading;
using System.Diagnostics;

namespace UnitTestUtils.UI
{
    /// <summary>
    /// Support for writing UI related tests.
    /// </summary>
    public class UITestHelper
    {
        #region make CTOR private
        private UITestHelper() { }
        #endregion

        /// <summary>
        /// Default timeout for tests in [s].
        /// </summary>
        public const int INT_DEFAULT_TIMEOUT = 5;

        /// <summary>
        /// Shuts down the current <see cref="Dispatcher"/> in case there is one running.
        /// </summary>
        public static void CleanupDispatcher()
        {
            if (Dispatcher.FromThread(Thread.CurrentThread) != null)
                Dispatcher.CurrentDispatcher.InvokeShutdown();
        }

        /// <summary>
        /// Returns default timeout for tests. In case a debugger is attached,
        /// the timeout is infinite.
        /// </summary>
        /// <returns></returns>
        public static TimeSpan GetTimeout()
        {
            TimeSpan timeout = TimeSpan.FromSeconds(INT_DEFAULT_TIMEOUT);
            if (Debugger.IsAttached)
            {
                timeout = TimeSpan.FromDays(1.0);
            }
            return timeout;
        }
    }
}
